#pragma once
#include "stdafx.h"

class Manager;
class Component;

class Object 
{
private:
	//Forbit default constructor in Object
	Object();
	Object(const Object&);
	
public:
	typedef boost::shared_ptr<Object> sPtr;
	typedef RequestMap LocalRequestMap;

	explicit Object(const ObjectName);
	virtual ~Object();

#ifdef _DEBUG
	stringstream Dump();
#endif

private:

	//Add the component to CompMap
	bool AddComponent(const CompPtr &);

	//abandon?
	void DestoryComponent(const CompName&, const CompId&);

	//Get the object name
	ObjectName GetName();

	// remove all requests for a given component
	void RemoveComponent(const CompId& id);
	
	//Receive a message from a componet. And search the local request table
	//to find if this object need this message. If need, then call the callback
	//function. 
	void ReceiveMessage(const ComponentRequest &, const Message &);

	//Register an request, add the request to local request table.
	void RegisterRequest(const ComponentRequest &, const RegisteredComponent &);

	//Math all component request with the new component. Call callback function if matched
	void RegisterComponent(const ComponentRequest&, const RegisteredComponent&);
	
	// object id
	ObjectName m_name;

	// component map
	CompMap m_components;

	// list of local requests
	LocalRequestMap m_localRequests;

	Manager* m_manager;
	
	// object manager is our friend
	friend class Manager;



};
